// import vue from '@vitejs/plugin-vue';
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import vitePlugin from './vite.plugin.js';

const resolve = (dir = '') => path.resolve(__dirname, dir)
const ICON_PATH = resolve('./src/assets/icons/svg')
// const WEBSITE_TITLE = '✨欢迎来到雨落的博客！🎉'
const WEBSITE_TITLE = '✨🎉'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const env = loadEnv(mode, process.cwd(), '')

  return {
    base: './',
    envPrefix: 'MOOD_',
    resolve: {
      alias: {
        '@': resolve('./src'),
        '@@': resolve('./src/ui'),
      },
    },
    build: {
      outDir: 'dist',
      assetsDir: 'assets',
      chunkSizeWarningLimit: 2000,
      sourcemap: true,
      manifest: true,
      rollupOptions: {}
    },
    plugins: [
      ...vitePlugin({
        htmlTransform: {
          title: WEBSITE_TITLE,
        },
        vitePlugionSvgIcons: {
          iconDirs: ICON_PATH,
        },
      }),
    ],
    server: {
      proxy: {
        '/api': {
          target: 'http://localhost:3000',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
      }
    },
    optimizeDeps: {
      include: [
        'vue',
        'vue-router',
        'pinia',
        'axios',
        'less',
        'less-loader',
      ],
    },
  }
})
